package com.example.demo.controller;


import com.example.demo.common.ResultBody;
import com.example.demo.common.response.BaseServiceResponse;
import com.example.demo.model.Carousel;
import com.example.demo.service.CarouselService;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/carousel")
public class CarouselController {
    @Resource
    CarouselService carouselService;
    @RequestMapping(value = "/list", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public BaseServiceResponse<?> getAllSample() {
        try {
            List<Carousel> list=carouselService.getAllCarousel();
          //  PageInfo<Carousel> pageInfo = new PageInfo<>(list);
            List<Map> l=new ArrayList<>();
            for(Carousel carousel:list) {
                Map map =new HashMap();
                map.put("img",carousel.getImage());
                l.add(map);
            }
            return new BaseServiceResponse<>(l,ResultBody.success,"100");
        }catch (Exception e) {
            return null;
        }
    }
}
